#!/bin/bash

CLASSPATH=/Applications/weka-3-6-4
TRAINING_FILE=$1
WEKA_PATH=$CLASSPATH/weka
WEKA_OUT=/tmp/weka_out


java -classpath $CLASSPATH:$CLASSPATH/weka.jar weka.attributeSelection.ChiSquaredAttributeEval \
     -i $TRAINING_FILE -s weka.attributeSelection.Ranker > $WEKA_OUT


LINE_TO_CUT=`cat $WEKA_OUT | grep -n Ranked | cut -d':' -f1`
TOTAL_LINES=`cat $WEKA_OUT | wc -l`

VAL=0
NUM_FEATURES=0
INDEX_COUNT=0

for i in `cat $WEKA_OUT | tail -n $((TOTAL_LINES - LINE_TO_CUT)) | head -n $((TOTAL_LINES - LINE_TO_CUT - 3))`; do
	
	TESTE=$((VAL % 3))
	
	if (( TESTE == 0 )); then
	
		FEATURE_VAL[NUM_FEATURES]=${i}
		NUM_FEATURES=$((NUM_FEATURES + 1))
	
	elif ((TESTE == 1)); then
	
		INDEX_VAL[INDEX_COUNT]=${i}
		INDEX_COUNT=$((INDEX_COUNT + 1))
	fi
		
	VAL=$((VAL + 1))
done

COUNT=0

for i in ${FEATURE_VAL[@]}; do
	
	RELEV_ARAY[${INDEX_VAL[$COUNT]}]=${i}
	COUNT=$((COUNT + 1))
done

echo ${RELEV_ARAY[@]} > /tmp/vetor_relevancia
